<template>
  <Layout class="p-5 bg-white">
    <Form
      :label-width="100"
      :rules="ruleValidate"
      ref="Interview.interview"
      :model="Interview.interview"
    >
      <Row>
        <Col span="8">
          <FormItem class="w-75" label="接待者">
            <!-- <i-col>
			      <Select
			        placeholder="请选择接待者"
			        v-model="Interview.interview.autor"
			        filterable
			        clearable
			      >
			        <Option v-for="item in autorList" :value="item.value"
			          >{{ item.label }}
			        </Option>
			      </Select>
			    </i-col> -->
            <label>{{ this.$route.params.row.autor }}</label>
          </FormItem>
          <FormItem class="w-75" label="到访描述" prop="des">
            <Input
              v-model="Interview.interview.des"
              placeholder="请输入到访描述"
            ></Input>
          </FormItem>
          <FormItem class="w-75" label="到访时间" prop="dateTime">
            <Date-picker
              format="yyyy-MM-dd HH:mm:ss"
              class="w-100"
              :value="Interview.interview.dateTime"
              type="datetime"
              @on-change="interviewTime"
              placeholder="请输入到访时间"
            ></Date-picker>
          </FormItem>
          <FormItem class="w-75" label="到访有效开关">
            <i-switch v-model="Interview.interview.flg"></i-switch>
          </FormItem>
          <!-- <FormItem class="w-25" label="线索ID">
			    <Input v-model="Interview.resource.id" placeholder="请输入线索ID"></Input>
			  </FormItem>
			  <FormItem class="w-25" label="应聘职位">
			    <Input v-model="Interview.resource.ypzw" placeholder="请输入应聘职位"></Input>
			  </FormItem>
			  <FormItem class="w-25" label="学生ID">
			    <Input v-model="Interview.student.id" placeholder="请输入学生ID"></Input>
			  </FormItem> -->

          <FormItem class="text-right">
            <Button v-preventReClick @click="submit" type="primary"
              >提交</Button
            >
            <Button @click="cancel" class="ml-2">取消</Button>
          </FormItem>
        </Col>
      </Row>
    </Form>
    <Loadding v-bind:loadinghuan="isSpinShow"></Loadding>
  </Layout>
</template>

<script>
import store from '../../common/store.js'
export default {
  data() {
    return {
      isSpinShow: false,
      ruleValidate: {
        des: [
          {
            required: true,
            message: '描述不能为空',
            trigger: 'blur',
            whitespace: true,
          },
        ],
        dateTime: [
          {
            required: true,
            message: '时间不能为空',
            trigger: 'blur',
            whitespace: true,
          },
        ],
      },
      allPermissions: [],
      Interview: {
        interview: {
          autor: '',
          des: '',
          dateTime: '',
          flg: true,
        },
        resource: {
          id: '',
          ypzw: '',
        },
        student: {
          id: '',
        },
      },
      autorList: [],
      isSelectAutor: '',
      User: {},
      gettime: '',
    }
  },
  created: function() {
    //在session中取出当前用户权限并校验绑定跟进人条件检索的选择框
    let currentUser = JSON.parse(sessionStorage.getItem('CURRENT_USER'))
    this.User = currentUser
    //从session中取出用户列表
    let userList = JSON.parse(localStorage.getItem('USER_LIST'))
    userList.forEach((user) => {
      let u = {
        value: user.userId,
        label: user.nickName,
      }
      this.autorList.push(u)
    })
    this.$data.Interview.interview.autor = this.$route.params.row.autorId
    this.$data.Interview.resource.id = this.$route.params.row.resourceId
    this.$data.Interview.resource.ypzw = this.$route.params.row.ypzw
    this.$data.Interview.student.id = this.$route.params.row.studentId
    this.getCurrentTime()
  },
  destroyed: function() {
    this.$router.push({
      name: 'resource',
    })
  },
  methods: {
    getCurrentTime() {
      //获取当前时间并打印
      var _this = this
      let yy = new Date().getFullYear()
      let mm = new Date().getMonth() + 1
      if (mm < 10) {
        mm = '0' + mm
      }
      let dd =
        new Date().getDate() < 10
          ? '0' + new Date().getDate()
          : new Date().getDate()
      let hh =
        new Date().getHours() < 10
          ? '0' + new Date().getHours()
          : new Date().getHours()
      let mf =
        new Date().getMinutes() < 10
          ? '0' + new Date().getMinutes()
          : new Date().getMinutes()
      let ss =
        new Date().getSeconds() < 10
          ? '0' + new Date().getSeconds()
          : new Date().getSeconds()
      this.gettime = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss
      this.Interview.interview.dateTime = this.gettime
    },
    interviewTime(change) {
      this.Interview.interview.dateTime = change
    },
    submit: function() {
      //   if (this.$data.addResource.student.name.length === 0) {
      //     this.message.error("账户名必须输入");
      //     return;
      //   }

      //   if (this.$data.user.password.length === 0) {
      //     this.message.error("密码必须输入");
      //     return;
      //   }

      //   if (this.$data.user.password !== this.$data.user.confirmPassword) {
      //     this.message.error("确认密码必须一致");
      //     return;
      //   }

      //   if (this.$data.user.tel.length === 0) {
      //     this.message.error("手机号必须输入");
      //     return;
      //   }

      //   if (this.$data.user.secId.length === 0) {
      //     this.message.error("身份证必须输入");
      //     return;
      //   }

      //   if (this.$data.user.role.length === 0) {
      //     this.message.error("角色必须选择");
      //     return;
      //   }
      if (this.$data.Interview.interview.des.trim().length === 0) {
        this.message.error('描述必须输入')
        return
      }
      if (this.$data.Interview.interview.dateTime.trim().length === 0) {
        this.message.error('时间必须输入')
        return
      }
      let self = this

      let param = {
        'interview.des': this.$data.Interview.interview.des,
        'interview.autor': this.$data.Interview.interview.autor,
        'interview.dateTime': this.$data.Interview.interview.dateTime,
        'interview.flg': this.$data.Interview.interview.flg,
        'interview.cu': this.$data.User.user.userId,

        'resource.id': this.$data.Interview.resource.id,
        'resource.ypzw': this.$data.Interview.resource.ypzw,
        'student.id': this.$data.Interview.student.id,
      }
      this.isSpinShow = true
      this.http
        .post({
          url: '/interview',
          param: param,
        })
        .then((data) => {
          this.isSpinShow = false
          self.message.info('新增成功')
          this.$tabs.close({ to: '/interview' })
        })
    },
    cancel: function() {
      this.$tabs.close({ to: '/interview' })
    },
  },
}
</script>

<style></style>
